package com.proxy.autoclick.checker.http.proxy;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;

import com.proxy.autoclick.common.util.Constants;
import com.proxy.autoclick.common.util.RandomNumUtil;
import com.proxy.autoclick.common.valueobject.Proxy;
/**
 * Handle checking google host class.
 *
 */
public class ClientExecuteProxyGoTarget extends ClientExecuteProxy{
	
	private String googleSearchLink;
	
	public ClientExecuteProxyGoTarget(HttpClient httpclient,Proxy myProxy,String googleSearchLink) throws URISyntaxException {
		super(httpclient,myProxy, getHttpGet(googleSearchLink));
		this.googleSearchLink = googleSearchLink;
	}
	
	private static HttpGet getHttpGet(String googleSearchLink) throws URISyntaxException
	{
		URI uri = new URI(googleSearchLink);
		HttpGet httpGet = new HttpGet(uri);
		return httpGet;
	}


	/**
	 * get valid display string for valid google proxy.
	 */
	public String getValidDisplayString() {
		return " Go to page: " + googleSearchLink + " (passed)";
	}

	/**
	 * get invalid display string for invalid google proxy.
	 */
	public String getInvalidDisplayString() {
//		return " Go to page: " + googleSearchLink + " (failed)";
		return "";
	}


	/**
	 * update validForGoogleHost to true for myProxy object
	 * set the update time in myProxy object.
	 */
	public void updateResultByValid(Proxy myProxy) {
		myProxy.setValidForGoogleHost(true);
		myProxy.setUpdateTimeForGoogleHost(new Date());
	}


	/**
	 * update validForGoogleHost 
	 * to false for myProxy object
	 */
	public void updateResultByInvalid(Proxy myProxy) {
		myProxy.setValidForGoogleHost(false);
	}


	public String[] getRegexString() {
		return Constants.GOOGLE_REGEX_STRING;
	}

	public int getVisitPageDelay() {
		return RandomNumUtil.getNumBetweenRange(mainFrame.getPageDelayFrom(), 
				mainFrame.getPageDelayTo())*1000;
	}

	@Override
	public void setValidOutputMessage(String message) {
		mainFrame.setTextAreaText(message);
	}

	@Override
	public void setInValidOutputMessage(String message) {
		mainFrame.setTextAreaText(message);
	}

}
